<?php

namespace Shahu\Common\common\jwtAuth;

use Shahu\Common\exception\AuthException;
use Shahu\Common\service\ApplicationService;

class Tenant
{
    /**
     * 检查租户
     * @return void
     * @throws AuthException
     */
    public static function checkTenant() : void
    {
        $tenant_id = $GLOBALS['tenant_id'] ?? '';
        if (empty($tenant_id)) {
            throw new AuthException('未知应用');
        }
        //检查租户是否存在
        $tenant = ApplicationService::getTenantCache($tenant_id);
        if (empty($tenant)) {
            throw new AuthException('未注册应用');
        }
    }
}
